<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>车辆调度</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../plugins/layui/css/layui.css" media="all" />
    <link rel="stylesheet" href="../plugins/layui/css/myPage.css">
</head>
<body class="layui-layout-body">


<blockquote class="layui-elem-quote"  >
    <div class=" layui-form" >
        <div class="layui-form-item"  >


            <div class="layui-input-inline" style="width: 130px">
                <select name="" lay-verify="required" id="khSearchKind" lay-filter="khSearchKind" >
                    <option value="">客户搜索类型</option>
                    <option value="khjc">客户简称</option>
                    <option value="khzjm">助记码</option>

                </select>

                <select name="" lay-filter="dingdan" id="ydSearchKind" >
                    <option value="">运单搜索类型</option>
                    <option value="cph">车牌号</option>
                    <option value="ydzt">运单状态</option>
                    <option value="ydh">运单号</option>
                    <option value="jsyxm">驾驶员姓名</option>


                </select>
            </div>
            <div class="layui-input-inline" id="searchContentCon">
                <select   class="layui-input" id="khSearchContent" lay-search> <option value="">请选择</option></select>

                <div id="ydSearchContentCon">
                    <select class="layui-input" id="ydSearchContent" lay-search> <option value="">请选择</option></select>
                </div>
            </div>



            <div class="layui-input-inline" style="width: 130px">
                <select name="city"  id="xlSearchKind" lay-filter="xlSearchKind" >
                    <option value="">线路搜索类型</option>
                    <option value="xlmc">线路名称</option>
                    <option value="xlzjm">助记码</option>
                </select>
                <select name="city" lay-verify="required" id="qySearchKind" lay-filter="qySearchKind">
                    <option value="">区域搜索类型</option>
                    <option value="qymc">区域名称</option>
                    <option value="qyzjm">助记码</option>
                </select>
            </div>

            <div class="layui-input-inline">
                <select   class="layui-input" id="xlSearchContent" lay-search> <option value="">请选择</option></select>
                <select   class="layui-input" id="qySearchContent" lay-search> <option value="">请选择</option></select>

            </div>

            <div class="layui-input-inline" style="width: 120px">
                <label class="layui-form-label">发车起始日期</label>
                <label class="layui-form-label">发车结束日期</label>
            </div>
            <div class="layui-input-inline">
                <input type="text"  class="layui-input"   id="searchQsrqContent">
                <input type="text"  class="layui-input" id="searchJsrqContent">
            </div>


            <div class="layui-input-inline" style="width: 80px">
                <button class="layui-btn layui-btn-normal" id="search">点击搜索</button>
                <button type="button" class="layui-btn layui-btn-normal" id="all">显示全部</button>
            </div>






        </div>
    </div>
</blockquote>
<div class="layui-row">
    <div class="layui-col-xs12">



        <script type="text/html" id="opera">

            {{#  if(d.ydzt == '已回车'){ }}

            {{#  if( getQueryVariable("R") == "false"){ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled"  disabled lay-event="detail">报账</button>
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" disabled="disabled" lay-event="posterror">退回</button>
            {{# }else{ }}


            {{#  if( getQueryVariable("BZ") == "false"){ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled"  disabled lay-event="detail">报账</button>
            {{# }else{ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs  "    lay-event="detail">报账</button>
            {{# } }}

            {{#  if( getQueryVariable("B") == "false"){ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" disabled="disabled" lay-event="posterror">退回</button>
            {{# }else{ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled "  disabled lay-event="posterror">退回</button>
            {{# } }}

            {{# } }}

            {{# }else if(d.ydzt == '已完成'||d.ydzt == '已报账'){ }}


            {{#  if( getQueryVariable("R") == "false"){ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled"  disabled lay-event="detail">报账</button>
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" disabled="disabled" lay-event="posterror">退回</button>
            {{# }else{ }}


            {{#  if( getQueryVariable("BZ") == "false"){ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled"  disabled lay-event="detail">报账</button>
            {{# }else{ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs  "    lay-event="detail">报账</button>
            {{# } }}

            {{#  if( getQueryVariable("B") == "false"){ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" disabled="disabled" lay-event="posterror">退回</button>
            {{# }else{ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs   "    lay-event="posterror" >退回</button>
            {{# } }}

            {{# } }}
            {{# }else if(d.ydzt.split('_')[1] == '审核中'){ }}
            {{#  if( getQueryVariable("R") == "false"){ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled"  disabled lay-event="detail">报账</button>
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" disabled="disabled" lay-event="posterror">退回</button>
            {{# }else{ }}


            {{#  if( getQueryVariable("BZ") == "false"){ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled"  disabled lay-event="detail">报账</button>
            {{# }else{ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs  "    lay-event="detail">报账</button>
            {{# } }}

            {{#  if( getQueryVariable("B") == "false"){ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" disabled="disabled" lay-event="posterror">退回</button>
            {{# }else{ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs   "    lay-event="posterror">退回</button>
            {{# } }}

            {{# } }}
            {{# }else { }}
            {{#  if( getQueryVariable("R") == "false"){ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled"  disabled lay-event="detail">报账</button>
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" disabled="disabled" lay-event="posterror">退回</button>
            {{# }else{ }}


            {{#  if( getQueryVariable("BZ") == "false"){ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled"  disabled lay-event="detail">报账</button>
            {{# }else{ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs  "    lay-event="detail">报账</button>
            {{# } }}

            {{#  if( getQueryVariable("B") == "false"){ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs layui-btn-disabled" disabled="disabled" lay-event="posterror">退回</button>
            {{# }else{ }}
            <button class="layui-btn layui-btn-normal layui-btn-xs   "    lay-event="posterror">退回</button>
            {{# } }}

            {{# } }}
            {{# } }}
        </script>
        <table id="table" lay-filter="Table"></table>
        <div id="laypage"></div>

        <script type="text/html" id="selectTpl_type">
            {{d.cph}}
        </script>

        <script type="text/html" id="zzc">

            {{# if(parseFloat(d.zzc) > parseFloat(d.zcsx)){ }}
            <div style="background:red;">{{d.zzc}}</div>
            {{# } else { }}
            {{d.zzc}}
            {{# } }}
        </script>
        <script type="text/html" id="ydztfix">
            {{# if(d.ydzt.indexOf('_') != -1){ }}
            {{d.ydzt.split('_')[1]}}
            {{#   }else{ }}
            {{d.ydzt }}
            {{# } }}
        </script>
    </div>
</div>





<script src="../plugins/layui/layui.js"></script>
<script src="../js/config.js"></script>
<script src="../js/tools.js"></script>
<script src="../js/autocomplete.js"></script>
<script>
    //JavaScript代码区域
    layui.use(['form' ,'table','jquery','layer','element','laydate','laypage'], function(){
        var form = layui.form;
        var table = layui.table;
        var $ = layui.$;
        var element = layui.element;
        var layer = layui.layer;
        var laydate = layui.laydate;
        var tableheight= 'full-200';
        var tablewidth = 90;
        var currentPage = 1;
        var cphData=[];
        var elemNull = {};
        var limitcount = 10;
        var curnum = 1;
        var laypage = layui.laypage;

        // elemNull.value = "&nbsp";
        // elemNull.text = "&nbsp";
        // cphData[0] = elemNull;
        var tablehead = [[ //表头
            {type:'numbers', title: '序号',  align:'center'}
            ,{field: 'ydh', title: '运单号' ,align:'center',width:160}
            ,{field: 'ydzt',templet:'#ydztfix' ,title: '运单状态',align:'center',width:100}

            ,{field: 'khjc', title: '客户简称' ,  align:'center',width:100}

            ,{field: 'qymc', title: '区域名称' ,  align:'center',width:100}
            ,{field: 'xlmc', title: '线路名称' ,  align:'center',width:160}
            ,{field: 'fcrq', title: '发车日期' ,align:'center',width:120}
            ,{field: 'bzrq', title: '报账日期' ,align:'center',width:120}
            ,{field:'cph',templet: '#selectTpl_type', title: '车牌号' ,align:'center',event: 'cph' ,width:110 }
            ,{field: 'leixing', title: '类型' ,align:'center',width:70}
            ,{field: 'jsyxm', title: '驾驶员' ,align:'center',width:100}
//            ,{field: 'jsysj', title: '驾驶员手机' ,align:'center'}
            ,{field: 'zcsx', title: '支出上限' ,align:'center',width:100}
//            ,{field: 'zsr', title: '总收入' ,align:'center',width:80}
            ,{field: 'zzc', title: '总支出' ,align:'center',templet:"#zzc",width:90}
            ,{ title:'操作', align:'center', toolbar: '#opera'}
        ]]

        //获取 cphData
        $.ajax({
            url: contextPath+"/car",
            type: "GET",
            contentType:"application/json;charset=utf-8",
            dataType:"json",
            success: function(res) {
                for(var i in res.list){
                    var elem = {};
                    elem.value = res.list[i].clid;
                    elem.text = res.list[i].cph;
                    cphData[i+1] = elem;
                }


            }

        });


        //  渲染搜索 select
        yewuSearch(form,$);
        yewuSearchydbzip(form,$,'bz');
        //执行一个laydate实例
        laydate.render({
            elem: '#ydrq' //指定元素
            ,format:'yyyy-MM-dd'
            ,theme:'#0099FF'

        });
        laydate.render({
            elem: '#searchQsrqContent' //指定元素
            ,format:'yyyy-MM-dd'
            ,theme:'#0099FF'
        });
        laydate.render({
            elem: '#searchJsrqContent' //指定元素
            ,format:'yyyy-MM-dd'
            ,theme:'#0099FF'

        });



//请求车牌号




        carAccount(curnum, limitcount);
        function carAccount(start,limitsize) {
            layui.use(['table','laypage','laydate'], function(){
                var table = layui.table,
                    laypage = layui.laypage;
                table.render({
                    url: contextPath + "waybill?bd=bz&pageNum="+start+"&pageSize="+limitsize,
                    elem: '#table',
                    height: tableheight,
                    page: false,
                    id: 'table',
                    cellMinWidth: tablewidth,
                    cols: tablehead,
                    done: function (res, curr,count) {
                        laypage.render({
                            elem: 'laypage'
                            , count: count
                            , curr: curnum
                            , limit: limitcount
                            , layout: ['prev', 'page', 'next', 'skip', 'count', 'limit']
                            , jump: function (obj, first) {
                                if (!first) {
                                    curnum = obj.curr;
                                    limitcount = obj.limit;
                                    //console.log("curnum"+curnum);
                                    //console.log("limitcount"+limitcount);
                                    //layer.msg(curnum+"-"+limitcount);
                                    carAccount(curnum, limitcount);
                                }
                            }
                        });
                    }
                });
            });
        }


        function carAccountsearch(start,limitsize) {
            layui.use(['table','laypage','laydate'], function(){
                var table = layui.table,
                    laypage = layui.laypage;
                table.render({
                    url: contextPath + "waybill?bd=bz&pageNum="+start+"&pageSize="+limitsize+"&"+$("#khSearchKind").val()+"="+$("#khSearchContent").val()+"&"+$("#xlSearchKind").val()+"="+$("#xlSearchContent").val()+"&"+$("#qySearchKind").val()+"="+$("#qySearchContent").val()+"&"+$("#ydSearchKind").val()+"="+$("#ydSearchContent").val()+"&qsrq="+$("#searchQsrqContent").val()+"&"+"jsrq="+$("#searchJsrqContent").val(),
                    dataType: "object",
                    elem: '#table',
                    height: tableheight,
                    page: false,
                    id: 'table',
                    cellMinWidth: tablewidth,
                    cols: tablehead,
                    done: function (res, curr,count) {
                        laypage.render({
                            elem: 'laypage'
                            , count: count
                            , curr: start
                            , limit: limitsize
                            , layout: ['prev', 'page', 'next', 'skip', 'count', 'limit']
                            , jump: function (obj, first) {
                                if (!first) {
                                    curnum = obj.curr;
                                    limitcount = obj.limit;
                                    //console.log("curnum"+curnum);
                                    //console.log("limitcount"+limitcount);
                                    //layer.msg(curnum+"-"+limitcount);
                                    carAccountsearch(curnum,limitcount);
                                }
                            }
                        });
                    }
                });
            });
        }

//刷新table实例
        $("#all").on('click',function () {
            curnum =1;
            carAccount(curnum, limitcount);
        });


        table.on('tool(Table)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data //获得当前行数据
                ,layEvent = obj.event; //获得 lay-event 对应的值
            if(obj.data.ydzt == "调度_审核中" || obj.data.ydzt == "快捷_审核中" || obj.data.ydzt == "报账_审核中" || obj.data.ydzt == "登记_审核中"){
                obj.data.ydzt = "审核中";
                // console.log(obj.data.ydzt)
            }
            if(obj.data.ydzt == "快捷_已完成"){
                obj.data.ydzt = "已完成";
            }
            if(layEvent === 'detail'){

                // console.log(obj.data);
                layer.open({
                    cancel: function(index, layero){
                        var faIndex = index;
                        if(obj.data.ydzt != "已完成" && obj.data.ydzt != "审核中"){

                            layer.confirm('确定要关闭么?未保存的信息将会丢失!', {icon: 3, title:'提示'}, function(index){
                                //do something
                                layer.close(index);
                                layer.close(faIndex);
                            });
                        }else {
                            layer.close(faIndex);
                        }

                        return false
                    },
                    type: 2,
                    title: '查看运单信息',
                    maxmin: true,
                    //点击遮罩关闭层
                    shadeClose:false,
                    area : ['1200px' , '800px'],
                    content: ['./lookBackCarAccount.html'],
                    success:function(layero,index){
                        // console.log(data);
                        var body = layer.getChildFrame('body',index);

                        for(var i in data){
                            body.contents().find("[name='"+i+"']").val(eval("data."+i));
                        }
                    },
                    end:function(){
                        carAccountsearch(curnum,limitcount);
                    }
                });
            } else if(layEvent === 'startcar'){

                $.ajax({
                    url: contextPath+"/waybill/"+data.ydid,
                    type: "PUT",
                    contentType:"application/json;charset=utf-8",
                    dataType:"json",
                    success: function(res) {
                        layer.msg(res.message);
                        carAccountsearch(curnum,limitcount);

                    }
                });

            }else if(layEvent === 'posterror') {
                layer.open({
                    cancel: function (index, layero) {
                        var faIndex = index;
                        layer.confirm('确定要关闭么?未保存的信息将会丢失!', {icon: 3, title: '提示'}, function (index) {
                            //do something
                            layer.close(index);
                            layer.close(faIndex);
                        });
                        return false
                    },
                    type: 2,
                    title: '退回',
                    maxmin: true,
                    //点击遮罩关闭层
                    area: ['80%', '80%'],
                    content: ['./postError.html'],
                    success: function (layero, index) {
                        // console.log(data);
                        var body = layer.getChildFrame('body', index);
                        data.comefrom = "bz";
                        for (var i in data) {
                            body.contents().find("[name='" + i + "']").val(eval("data." + i));
                        }
                    },
                    end: function () {
                        carAccountsearch(curnum,limitcount);
                    }
                });
            }

        });

        // table.on('edit(Table)', function(obj){ //注：edit是固定事件名，test是table原始容器的属性 lay-filter="对应的值"
        //
        //     console.log(obj);
        // });



//搜索
        $("#search").on('click',function(){
            if($("#searchQsrqContent").val() != "" && $("#searchJsrqContent").val() != ""){
                if(!checkEndTime($("#searchQsrqContent").val(),$("#searchJsrqContent").val())){
                    layer.msg("起始日期小于结束日期!");
                }else {
                    curnum = 1;
                    layui.use(['table','laypage','laydate'], function(){
                        var table = layui.table,
                            laypage = layui.laypage;
                        table.render({
                            url: contextPath + "waybill?bd=bz&pageNum="+curnum+"&pageSize="+limitcount+"&"+$("#khSearchKind").val()+"="+$("#khSearchContent").val()+"&"+$("#xlSearchKind").val()+"="+$("#xlSearchContent").val()+"&"+$("#qySearchKind").val()+"="+$("#qySearchContent").val()+"&"+$("#ydSearchKind").val()+"="+$("#ydSearchContent").val()+"&qsrq="+$("#searchQsrqContent").val()+"&"+"jsrq="+$("#searchJsrqContent").val(),
                            dataType: "object",
                            elem: '#table',
                            height: tableheight,
                            page: false,
                            id: 'table',
                            cellMinWidth: tablewidth,
                            cols: tablehead,
                            done: function (res, curr,count) {
                                laypage.render({
                                    elem: 'laypage'
                                    , count: count
                                    , curr: curnum
                                    , limit: limitcount
                                    , layout: ['prev', 'page', 'next', 'skip', 'count', 'limit']
                                    , jump: function (obj, first) {
                                        if (!first) {
                                            curnum = obj.curr;
                                            limitcount = obj.limit;
                                            //console.log("curnum"+curnum);
                                            //console.log("limitcount"+limitcount);
                                            //layer.msg(curnum+"-"+limitcount);
                                            carAccountsearch(curnum,limitcount);
                                        }
                                    }
                                });
                            }
                        });
                    });
                }
            }else if($("#searchQsrqContent").val() != "" && $("#searchJsrqContent").val() == ""){
                layer.msg("结束日期不能为空！");
            }else if($("#searchQsrqContent").val() == "" && $("#searchJsrqContent").val() != ""){
                layer.msg("起始日期不能为空！");
            }else {
                curnum = 1;
                layui.use(['table','laypage','laydate'], function(){
                    var table = layui.table,
                        laypage = layui.laypage;
                    table.render({
                        url: contextPath + "waybill?bd=bz&pageNum="+curnum+"&pageSize="+limitcount+"&"+$("#khSearchKind").val()+"="+$("#khSearchContent").val()+"&"+$("#xlSearchKind").val()+"="+$("#xlSearchContent").val()+"&"+$("#qySearchKind").val()+"="+$("#qySearchContent").val()+"&"+$("#ydSearchKind").val()+"="+$("#ydSearchContent").val()+"&qsrq="+$("#searchQsrqContent").val()+"&"+"jsrq="+$("#searchJsrqContent").val(),
                        dataType: "object",
                        elem: '#table',
                        height: tableheight,
                        page: false,
                        id: 'table',
                        cellMinWidth: tablewidth,
                        cols: tablehead,
                        done: function (res, curr,count) {
                            laypage.render({
                                elem: 'laypage'
                                , count: count
                                , curr: curnum
                                , limit: limitcount
                                , layout: ['prev', 'page', 'next', 'skip', 'count', 'limit']
                                , jump: function (obj, first) {
                                    if (!first) {
                                        curnum = obj.curr;
                                        limitcount = obj.limit;
                                        //console.log("curnum"+curnum);
                                        //console.log("limitcount"+limitcount);
                                        //layer.msg(curnum+"-"+limitcount);
                                        carAccountsearch(curnum,limitcount);
                                    }
                                }
                            });
                        }
                    });
                });
            }
        });



    });





</script>
</body>
</html>